/*
 * OPIAM Suite
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */

package opiam.admin.faare.config.javabeans;


/**
 * Class corresponding to the "link" element of the views.xml file.
 * This defines a link between two logic view levels.
 */
public class JBLink implements java.io.Serializable
{
    /** Keyword for current level object. */
    public static final String OP_THIS = "this";

    /** Keyword for previous level object. */
    public static final String OP_SUPER = "super";

    /** Keyword for member typed link. */
    public static final String TYPE_MEMBER = "member";

    /** Keyword for AND typed link. */
    public static final String TYPE_AND = "AND";

    /*DW/2648/BeginPatch*/
    /** Keyword for AND_NOT typed link. */
    public static final String TYPE_AND_NOT = "AND_NOT";
    /*DW/2648/EndPatch*/

    /** Keyword for base search typed link. */
    public static final String TYPE_SCOPE_BASE = "scope_base";

    /** Keyword for one level search typed link. */
    public static final String TYPE_SCOPE_ONE_LEVEL = "scope_one_level";

    /** Keyword for subtree search typed link. */
    public static final String TYPE_SCOPE_SUBTREE = "scope_subtree";

    /** Link type. */
    private String type;

    /** Link filter value. */
    private String value;

    /** Creates new JBLink. */
    public JBLink()
    {
    }

    /**
     * Returns the link type.<br>
     * On of TYPE_AND or TYPE_MEMBER.
     * @return link type
     */
    public String getType()
    {
        return type;
    }

    /**
     * Returns the link filter value.
     * @return value
     */
    public String getValue()
    {
        return value;
    }

    /**
     * Sets the link type.
     * @param atype The type to set. One of TYPE_AND or TYPE_MEMBER.
     */
    public void setType(String atype)
    {
        this.type = atype;
    }

    /**
     * Sets the link filter value.
     * @param avalue The value to set
     */
    public void setValue(String avalue)
    {
        this.value = avalue;
    }

    /**
     * Gets the first part of the link filter value.
     *
     * @return part of value
     */
    public String getValueBeforeEqual()
    {
        try
        {
            int equal = value.indexOf("=");

            return value.substring(0, equal).trim();
        }
        catch (Exception e)
        {
            return null;
        }
    }

    /**
     * Gets the second part of the link filter value.
     *
     * @return part of value
     */
    public String getValueAfterEqual()
    {
        try
        {
            int equal = value.indexOf("=");

            return value.substring(equal + 1).trim();
        }
        catch (Exception e)
        {
            return null;
        }
    }

    /**
     * Displays the link.
     *
     * @return String formatted definition of the link.
     */
    @Override
	public String toString()
    {
        StringBuffer buf = new StringBuffer();
        java.util.Iterator it = null;

        buf.append("            type = ");
        buf.append(type);
        buf.append(System.getProperty("line.separator"));
        buf.append("         value = ");
        buf.append(value);
        buf.append(System.getProperty("line.separator"));

        return buf.toString();
    }

    // end of toString method
}
